/**
 * Created by IntelliJ IDEA.
 * User: mengrv
 * DateTime: 2018/6/20 15:44
 */
import electron from 'electron';

const {remote} = electron;
const {Menu, dialog, nativeImage} = remote;
const iconImage = nativeImage.createFromPath('./build/icons/256x256.png');
const shell = remote.shell;
const pkg = require('../../../package.json');
const OSX = process.platform === 'darwin';
export var appMenu = {
	menubar: [],
	ready: function() {
		var self = this;
		self.addMenuOSX();
		self.menubar.push(
			{
				label: "文件",
				submenu: [
					{
						label: "读取文件"
					}
				]
			},
			{
				label: "设置",
				submenu: [
					{
						label: "黑色背景"
					}
				]
			},
			{
				label: "窗口",
				submenu: [
					{
						role: 'togglefullscreen',
					},
					{ type: 'separator' },
					{
						label: '窗口始终置顶',
						accelerator: 'CmdOrCtrl+Shift+T',
						type: 'checkbox',
						checked: false,
						click: function(item, focusedWindow) {
							focusedWindow.setAlwaysOnTop(!focusedWindow.isAlwaysOnTop());
						},
					},
				]
			},
			{
				label: "帮助",
				role: 'help',
				submenu: [
					{
						label: "关于",
						click: function(item, focusedWinsdow) {
							dialog.showMessageBox(focusedWinsdow, {
								title: "关于我们",
								icon: iconImage,
								message: `${pkg.name} 版本：${pkg.version}`,
								detail: pkg.description + '\n\n'
								+ 'Electron版本: ' + process.versions.electron + '\n'
								+ 'Chromium版本: ' + process.versions.chrome + '\n'
								+ 'V8版本: ' + process.versions.v8 + '\n'
								+ '开发者：' + pkg.author + '\n'
								+ 'Node.js版本: ' + process.versions.node,
								buttons: [
									"ok", "cancel"
								],
							})
						}
					}
				]
			}
		)
		Menu.setApplicationMenu(Menu.buildFromTemplate(self.menubar));
	},
	addMenuOSX: function() {
		if(!OSX) {
			return;
		}
		var self = this;
		self.menubar.push({
			label: "新菜单",
			role: 'window',
			submenu: [
				{
					label: "退出",
					accelerator: 'CmdOrCtrl+Q',
					click: function(item, focusedWindow) {
						focusedWindow.close();
					},
				}
			]
		})
	}
}
